package wiki.tools.vidition.droid;

import java.util.ArrayList;
import wiki.tools.vidition.droid.util.bean.NewsItem;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class RSSNewsAdapter extends BaseAdapter {
	private LayoutInflater layoutInflater;
	private ArrayList<NewsItem> rss;

	public RSSNewsAdapter(Context c) {
		layoutInflater = (LayoutInflater) c
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return rss.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (null == convertView) {
			convertView = layoutInflater.inflate(R.layout.newslist, parent,
					false);
		}

		TextView title = (TextView) convertView
				.findViewById(R.id.newslist_title);
		TextView desc = (TextView) convertView.findViewById(R.id.newslist_desc);

		title.setText(rss.get(position).title);
		desc.setText(rss.get(position).description);
		
		return convertView;
	}
	
	public void setData(ArrayList<NewsItem> rss) {
		this.rss = rss;
		notifyDataSetChanged();
	}
}
